import com.sun.tools.jconsole.JConsoleContext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-05-17
 * Time: 20:23
 */
class MyEncryption {
    private String parrword;

    public void setParrword(String pwd) {
        parrword = pwd;
    }

    public String EncodeStr(String s) {

        char[] c = s.toCharArray();
        char[] p = parrword.toCharArray();
        for (int i = 0, j = 0; i < c.length; i++, j++) {
            if (j >= p.length) j = 0;
            c[i] = (char) (c[i] ^ p[j]);
        }
        return new String(c);
    }

    public String DecodeStr(String s) {
        return EncodeStr(s);
    }


    public static void main(String[] args) {
        MyEncryption e = new MyEncryption();
        String s = "My name is XXX";
        e.setParrword("wbgsn");
        String encodedStr = e.EncodeStr(s);
        System.out.println("原文内容如下：" + s);
        System.out.println("加密后的密文。");
        System.out.println(encodedStr);
        String decodedStr = e.DecodeStr(encodedStr);
        System.out.println("解密后的原文：");
        System.out.println(decodedStr);
    }
}
